package com.bbs.db.impl;

import com.bbs.db.iface.BoardinfoDao;
import com.bbs.db.pers.Boardinfo;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * @time Nov 12, 2009, 9:17:22 PM
 * @author fdcube
 */
public class BoardinfoImpl extends HibernateDaoSupport implements BoardinfoDao {

    public boolean AddBoard(Boardinfo value) {
        try {
            this.getHibernateTemplate().save(value);
            return true;
        } catch (DataAccessException dataAccessException) {
            logger.error(dataAccessException);
            return false;
        }
    }

    public boolean DeleteBoard(Boardinfo value) {
        try {
            Boardinfo btmp = this.getHibernateTemplate().get(Boardinfo.class, value.getBid());
            this.getHibernateTemplate().delete(btmp);
            return true;
        } catch (DataAccessException dataAccessException) {
            logger.error(dataAccessException);
            return false;
        }
    }

    public List<Boardinfo> FindBoards() {
        System.out.println("Get Boards-----BoardinfoImpl");
        return this.getHibernateTemplate().find("FROM Boardinfo ORDER BY bid");
    }

    public List<Boardinfo> FindBoard(Boardinfo value) {
        return this.getHibernateTemplate().findByNamedParam("FROM Boardinfo as b WHERE b.bid =:bid", "bid", value.getBid());
    }

    public boolean UpdateBoard(Boardinfo value) {
        try {
            this.getHibernateTemplate().merge(value);
            return true;
        } catch (DataAccessException dataAccessException) {
            logger.error(dataAccessException);
            return false;
        }
    }
}
